package com.fms.data.editor;

import java.io.File;
import java.io.IOException;

import com.fms.model.ILogger;
import com.fms.model.domain.FlowSheet;
import com.fms.model.editor.IFlowSheetEditor;
import com.fms.model.properties.AbstractProperties;

public class ExcelSheetEditor implements IFlowSheetEditor
{
	private static final String	EDITOR_COMMAND_EXECUTE	= "editor.command.execute";
	private AbstractProperties	props;
	private ILogger	logger;

	public ExcelSheetEditor(AbstractProperties _props, ILogger _logger)
	{
		this.props = _props;
		this.logger = _logger;
	}

	@Override
	public void edit(FlowSheet sheet)
	{
		String executeCommand = props.getProperty(EDITOR_COMMAND_EXECUTE);
		
		
		if(executeCommand != null)
		{
		
			try
			{
				System.out.println(executeCommand + " \"" + new File(sheet.getFileName()).getAbsolutePath() + "\"");
				Runtime.getRuntime().exec(executeCommand + " \"" + new File(sheet.getFileName()).getAbsolutePath() + "\"");
			} 
			catch (IOException e)
			{
				logger.log("There was a problem opening the flowsheet.\nCheck that the flowsheet is not already open.");
			}
		}
		else
		{
			logger.log("The execute command was not specified. The item " + EDITOR_COMMAND_EXECUTE + " was not found in the configuration file." );
		}
	}

}
